local skels = {}

local zuige = fk.CreateSkill{
    name = "XD__zuige"
}
Fk:loadTranslationTable{
    ["XD__zuige"] = "罪歌",
    [":XD__zuige"] = "出牌阶段开始时，或当你受到伤害后，你可以选择未选择过的一项：令一名角色摸两张牌；或令一名角色弃置两张牌；或令一名角色回复1点体力；或令一名角色受到1点伤害；或令一名角色将武将牌调整至背面朝上并横置；或令一名角色复原武将牌；或明置身份牌，然后重置其余的选项。",
    ["#XD__zuige"] = "罪歌：你可以执行未选择过的一项",
    ["XD__zuige_active"] = "罪歌",
    ["#XD__zuige1"] = "令一名角色摸两张牌",
    ["#XD__zuige2"] = "令一名角色弃置两张牌",
    ["#XD__zuige3"] = "令一名角色回复1点体力",
    ["#XD__zuige4"] = "令一名角色受到1点伤害",
    ["#XD__zuige5"] = "令一名角色翻至背面并横置",
    ["#XD__zuige6"] = "令一名角色复原武将牌",
    ["#XD__zuige7"] = "明置身份牌并重置其余项",
}
local spec = {
    on_cost = function (self, event, target, player, data)
        local bool, dat = player.room:askToUseActiveSkill(player, {
            skill_name = "XD__zuige_active",
            skip = true,
            prompt = "#XD__zuige"
        })
        if bool and dat then
            event:setCostData(self, {tos = dat.targets, choice = dat.interaction})
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local dat = event:getCostData(self)
        local to = dat.tos[1]
        switch(dat.choice,{
            ["#XD__zuige1"] = function ()
                to:drawCards(2, zuige.name)
            end,
            ["#XD__zuige2"] = function ()
                room:askToDiscard(to, {
                    max_num = 2,
                    min_num = 2,
                    include_equip = true,
                    cancelable = false,
                    skill_name = zuige.name,
                })
            end,
            ["#XD__zuige3"] = function ()
                room:recover{
                    who = to,
                    recoverBy = player,
                    num = 1,
                    skillName = zuige.name,
                }
            end,
            ["#XD__zuige4"] = function ()
                room:damage{
                    to = to,
                    damage = 1,
                    skillName = zuige.name,
                }
            end,
            ["#XD__zuige5"] = function ()
                to:turnOver()
                to:setChainState(true)
            end,
            ["#XD__zuige6"] = function ()
                to:reset()
            end,
            ["#XD__zuige7"] = function ()
                room:setPlayerProperty(player, "role_shown", true)
                room:broadcastProperty(player, "role")
                room:setPlayerMark(player, zuige.name, {})
            end,
        })
        room:addTableMarkIfNeed(player, zuige.name, dat.choice)
    end,
}
zuige:addEffect(fk.EventPhaseStart, {
    anim_type = "control",
    can_trigger = function (self, event, target, player, data)
        return target == player and player:hasSkill(zuige.name) and player.phase == Player.Play
    end,
    on_cost = spec.on_cost,
    on_use = spec.on_use,
})
zuige:addEffect(fk.Damaged, {
    anim_type = "control",
    can_trigger = function (self, event, target, player, data)
        return target == player and player:hasSkill(zuige.name)
    end,
    on_cost = spec.on_cost,
    on_use = spec.on_use,
})
table.insert(skels, zuige)

local zuige_active = fk.CreateSkill{
    name = "XD__zuige_active"
}
zuige_active:addEffect("active", {
    interaction = function (self, player)
        local choices, all_choices = {}, {}
        for i = 1, 7, 1 do
            local str = "#XD__zuige"..i
            if not table.contains(player:getTableMark(zuige.name), str) then
                table.insert(choices, str)
            end
            table.insert(all_choices, str)
        end
        return UI.ComboBox{ choices = choices, all_choices = all_choices }
    end,
    card_num = 0,
    card_filter = Util.FalseFunc,
    target_filter = function (self, player, to_select, selected, selected_cards, card, extra_data)
        if self.interaction.data and #selected == 0 then
            if self.interaction.data == "#XD__zuige2" then
                return not to_select:isNude()
            elseif self.interaction.data == "#XD__zuige3" then
                return to_select:isWounded()
            elseif self.interaction.data == "#XD__zuige5" then
                return to_select.faceup
            elseif self.interaction.data == "#XD__zuige6" then
                return not to_select.faceup or to_select.chained
            elseif self.interaction.data == "#XD__zuige7" then
                return false
            else
                return true
            end
        end
    end,
    feasible = function (self, player, selected, selected_cards, card)
        if self.interaction.data then
            if self.interaction.data == "#XD__zuige7" then
                return true
            else
                return #selected == 1
            end
        end
    end,
})
table.insert(skels, zuige_active)

return skels